<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
#use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('wechat_auths')) return;
        Schema::create('wechat_auths', function (Blueprint $table) {
            $table->id()->unsigned()->autoIncrement();
            $table->string('unionid', 50)->default('')->comment('unionid');
            $table->string('session_key', 50)->default('')->comment('session_key');
            $table->string('openid', 50)->default('')->comment('openid');
            $table->string('nick_name', 50)->default('')->comment('昵称');
            $table->string('avatar')->default('')->comment('头像');
            $table->string('gender', 10)->default('')->comment('性别');
            $table->string('province', 50)->default('')->comment('省');
            $table->string('city', 150)->default('')->comment('市');
            $table->string('country', 50)->default('')->comment('国家');
            $table->string('mobile', 11)->default('')->comment('手机号');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
        DB::statement("ALTER TABLE `wechat_auths` COMMENT '微信授权信息'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) Schema::dropIfExists('wechat_auths');
    }
};
